import { createApp } from 'vue'
import ant from 'ant-design-vue'
import 'ant-design-vue/dist/reset.css'
import './style/app.css'
import './mock/mock'
import router from './router'
import pinia from './store'
import './utils/permission'
import VueParticles from 'vue-particles'
import './defineRoute'
import App from './App.vue'

let instance = null;
function render(props = {}) {
  const { container } = props;
  instance = createApp(App)
  instance.use(ant)
  instance.use(router)
  instance.use(pinia)
  instance.use(VueParticles)
  instance.mount(container ? container.querySelector("#app") : "#app")
}

export async function bootstrap() {
  console.log('微应用：bootstrap')
}
export async function mount(props) {
  // 获取主应用传入数据
  console.log('微应用：mount', props.container)
  render(props)
}
export async function unmount(props) {
  const { container } = props;
  instance.unmount(container ? container.querySelector("#app") : "#app");
  instance = null;
}

// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
  render();
} else {
  window.__webpack_public_path__ = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
}
